//
//  YJNoticeLabel.m
//  提示语封装
//
//  Created by yuanjiang on 2017/6/8.
//  Copyright © 2017年 YuanJiang. All rights reserved.
//

#import "YJNoticeLabel.h"

@implementation YJNoticeLabel

+ (instancetype)message:(NSString *)message delaySecond:(CGFloat)second
{
    CGFloat kwid = [UIScreen mainScreen].bounds.size.width;
    CGFloat khei = [UIScreen mainScreen].bounds.size.height;
    
    YJNoticeLabel *_labelView = nil;
    if (_labelView == nil) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
        label.backgroundColor = [UIColor clearColor];
        label.text = message;
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:14];
        label.numberOfLines = 0;
        label.textAlignment = NSTextAlignmentCenter;
        CGFloat wid = [label.text boundingRectWithSize:CGSizeMake(kwid / 4 * 3, 33)  options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil].size.width;
        CGFloat hei = [label.text boundingRectWithSize:CGSizeMake(wid, FLT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil].size.height;
        [label setFrame:CGRectMake(10, 10, wid, hei)];
        
        _labelView = [[YJNoticeLabel alloc] initWithFrame:CGRectMake(kwid/2 - wid/2, khei/2 - hei/2, wid + 20, hei + 20)];
        [_labelView addSubview:label];
        _labelView.backgroundColor = [UIColor blackColor];
        _labelView.alpha = 0.7;
        _labelView.layer.cornerRadius = 8;
        _labelView.clipsToBounds = YES;
    }
    [_labelView removeFromItsSuperVIew:_labelView second:second];
    return  _labelView;
}

- (void)removeFromItsSuperVIew:(YJNoticeLabel *)labelView second:(CGFloat)second{
    
    __weak typeof(labelView) weakself = labelView;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(second * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [weakself removeFromSuperview];
    });
    
}






















@end
